@startuml
participant "Application\nCode" as A

skinparam Participant {
  RoundCorner 10

  BackgroundColor<<LLMRails >> 76b900
  FontColor<<LLMRails>> white
  BorderColor<<LLMRails>> green
}


participant LLMRails <<LLMRails>>
participant "Vector DB" as V


A->LLMRails: <<USER MESSAGE>>
activate LLMRails



  LLMRails->V: search canonical form examples
  activate V
  return Top K examples

  LLMRails->V: search flow examples
  activate V
  return Top K examples

  LLMRails->V: search bot message examples
  activate V
  return Top K examples

  LLMRails->LLM: TaskPrompt [generate_intent_steps_message]
  activate LLM
  return <<USER CANONICAL FORM>>\n<<NEXT STEP>>\n<<BOT MESSAGE>>


  alt If a flow matches the user canonical form

  LLMRails->LLMRails: <<NEXT STEP>> from flow

  else If not, use the LLM-generated one

  LLMRails->LLMRails: <<NEXT STEP>> from LLM

  end

  alt If there is a pre-defined message
  LLMRails->LLMRails: <<BOT MESSAGE>> from predefined message

  else If <<NEXT STEP>> from LLM was used
  LLMRails->LLMRails: <<BOT MESSAGE>> from LLM

  else Otherwise, ask the LLM again to generate the message
    LLMRails->LLM: TaskPrompt [generate_bot_message]
    activate LLM
    return <<BOT MESSAGE>>

  end


return #green <<BOT MESSAGE>>

participant LLM
hide footbox
hide stereotype
scale 2
@enduml
